﻿using System;
using Caliburn.Micro;
using PocketBook.Model;

namespace PocketBook.ViewModels
{
    public interface IDesignSite
    {
        IDesign Design { get; set; }
    }

    public class PageSiteViewModel : PropertyChangedBase, IDesignSite
    {
        private IDesign _design;

        public event EventHandler SiteContentChanged;

        public PageSiteViewModel(string displayName)
        {
            DisplayName = displayName;
        }

        public string DisplayName 
        { 
            get; private set;
        }

        public IDesign Design
        {
            get { return _design; }
            set
            {
                if (value == Design) return;

                _design = value;

                NotifyOfPropertyChange(() => Design);
                SiteContentChanged(this, EventArgs.Empty);
            }
        }

        public void SwapDesignWith(PageSiteViewModel other)
        {
            if (ReferenceEquals(this, other)) return;

            var originalDesign = Design;
            Design = other.Design;
            other.Design = originalDesign;
        }
    }
}